﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace InputBoxes.Controls
{
    [ToolboxItem(false)]
    public class StaticTextBox : TextBox, IStaticTextBox
    {
        public StaticTextBox()
        {
            Info = new StaticTextInfo(this);
        }

        #region Implementation of IStaticTextBox

        public StaticTextInfo Info { get; set; }

        public event EventHandler Changed;

        public void OnChanged()
        {
            if (Changed != null) Changed(this, EventArgs.Empty);
        }

        public int CalculateWidth()
        {
            using (Graphics g = CreateGraphics())
            {
                int width = (int)g.MeasureString(Text, Font).Width + Margin.Left + Margin.Right;
                return width;
            }
        }

        #endregion
    }
}